﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DLL.Entities;
using System.Xml.Serialization;
using System.IO;
using DLL;

namespace RAD
{
    public partial class RAD_Form : Form
    {       

        public RAD_Form()
        {
            InitializeComponent();
        }

        string cwd = System.IO.Directory.GetCurrentDirectory();

        private void btnLockOn_Click(object sender, EventArgs e)
        {
           
            if (rdBtnBirds.Checked)
            {
                txtSpeed.Text = Convert.ToString(Utility.RandomNumber(50, 100));                
                txtDirection.Text = Convert.ToString(Utility.RandomNumber(10, 1000));              
                txtAltitude.Text = Convert.ToString(Utility.RandomNumber(100, 2000));                
                txtDistance.Text = Convert.ToString(Utility.RandomNumber(10, 5000));                
            }
            else if(rdBtnDragon.Checked)
            {
                txtSpeed.Text = Convert.ToString(Utility.RandomNumber(100, 700));
                txtDirection.Text = Convert.ToString(Utility.RandomNumber(10, 1000));
                txtAltitude.Text = Convert.ToString(Utility.RandomNumber(100, 5000));
                txtDistance.Text = Convert.ToString(Utility.RandomNumber(10, 5000));       
            }
            else if (rdBtnFightJet.Checked)
            {
                txtSpeed.Text = Convert.ToString(Utility.RandomNumber(200, 900));
                txtDirection.Text = Convert.ToString(Utility.RandomNumber(10, 1000));
                txtAltitude.Text = Convert.ToString(Utility.RandomNumber(1000, 5000));
                txtDistance.Text = Convert.ToString(Utility.RandomNumber(10, 5000));
            }
            else
            {
                MessageBox.Show("Select a target");
            }


            Radar Radar_Obj = new Radar();
            
            Radar_Obj.Altitude = txtAltitude.Text;
            Radar_Obj.Direction = txtDirection.Text;
            Radar_Obj.Distance = txtDistance.Text;
            Radar_Obj.Speed = txtSpeed.Text;

              
            cwd = cwd.Replace("\\bin\\Debug","");
            XmlSerializer serialization = new XmlSerializer(typeof(Radar));
            XMLHandler.WriteXML(Radar_Obj, "Radar_Serialized.xml", serialization);
            MessageBox.Show("Target Locked! ");           
        }      
         
         

               

        private void btnScan_Click(object sender, EventArgs e)
        {
            Random randomNumber = new Random();
            int newNumber = randomNumber.Next(4);

            switch (newNumber)
            {
                case 1:
                    rdBtnBirds.Checked = true;                    
                    break;
                case 2:
                    rdBtnDragon.Checked = true;                    
                    break;
                case 3:
                    rdBtnFightJet.Checked = true;                    
                    break;
            } 
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            
            RadStat radStatus = new RadStat();
            radStatus.radStatus = Convert.ToString(DateTime.Now);
            XmlSerializer serialization = new XmlSerializer(typeof(RadStat));
            XMLHandler.WriteXML(radStatus, "RadStat_Serialized.xml", serialization);
           
        }

       
    }
}    

        
    
